package com.yzr.common.collection.set;

import java.math.BigDecimal;
import java.util.HashSet;
import java.util.Objects;

/**
 * @description
 * @author: yx-0173
 * @date: 2021-08-09 14:53
 **/
@SuppressWarnings({"all"})
public class HashSetConnect {
    public static void main(String[] args) {

        HashSet<Employee> employees = new HashSet<>();
        Employee jack = new Employee("jack", BigDecimal.valueOf(8000), new MyDate(2021, 07, 06));
        Employee tom = new Employee("tom", BigDecimal.valueOf(8000), new MyDate(2021, 07, 06));
        Employee jack1 = new Employee("jack", BigDecimal.valueOf(9000), new MyDate(2021, 07, 06));


        System.out.println(employees.add(jack));
        System.out.println(employees.add(tom));
        System.out.println(employees.add(jack1));
        System.out.println(employees);


    }
}

class Employee {
    private String name;

    private BigDecimal sal;

    private MyDate birthDay;

    public Employee(String name, BigDecimal sal, MyDate birthDay) {
        this.name = name;
        this.sal = sal;
        this.birthDay = birthDay;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public BigDecimal getSal() {
        return sal;
    }

    public void setSal(BigDecimal sal) {
        this.sal = sal;
    }

    public MyDate getBirthDay() {
        return birthDay;
    }

    public void setBirthDay(MyDate birthDay) {
        this.birthDay = birthDay;
    }

    @Override
    public String toString() {
        return "Employee{" +
                "name='" + name + '\'' +
                ", sal=" + sal +
                ", birthDay=" + birthDay +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Employee employee = (Employee) o;
        return Objects.equals(name, employee.name) &&
                Objects.equals(birthDay, employee.birthDay);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, birthDay);
    }

}

class MyDate {
    private Integer year;

    private Integer month;

    private Integer day;

    public MyDate(Integer year, Integer month, Integer day) {
        this.year = year;
        this.month = month;
        this.day = day;
    }

    public Integer getYear() {
        return year;
    }

    public void setYear(Integer year) {
        this.year = year;
    }

    public Integer getMonth() {
        return month;
    }

    public void setMonth(Integer month) {
        this.month = month;
    }

    public Integer getDay() {
        return day;
    }

    public void setDay(Integer day) {
        this.day = day;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        MyDate myDate = (MyDate) o;
        return Objects.equals(year, myDate.year) &&
                Objects.equals(month, myDate.month) &&
                Objects.equals(day, myDate.day);
    }

    @Override
    public int hashCode() {
        return Objects.hash(year, month, day);
    }
}
